<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="最近深度系统编译jni太卡，基本编译2次要重启一次，决定重装麒麟系统，重装显卡驱动和cuda10.1和cudnn和重新编译tensorflow1.13.2安装包。 参考如下：Ubuntu18.04安装nvidia显卡驱动How to install the NVIDIA drivers on Ubuntu 18.04 Bionic Beaver LinuxUbuntu18.04下安装Nvidia驱">
<meta property="og:type" content="article">
<meta property="og:title" content="tf1.13环境搭建">
<meta property="og:url" content="http://zengzheming.gitee.io/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/index.html">
<meta property="og:site_name" content="曾哲明的博客">
<meta property="og:description" content="最近深度系统编译jni太卡，基本编译2次要重启一次，决定重装麒麟系统，重装显卡驱动和cuda10.1和cudnn和重新编译tensorflow1.13.2安装包。 参考如下：Ubuntu18.04安装nvidia显卡驱动How to install the NVIDIA drivers on Ubuntu 18.04 Bionic Beaver LinuxUbuntu18.04下安装Nvidia驱">
<meta property="og:image" content="http://zengzheming.gitee.io/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20190816090744338.png">
<meta property="og:image" content="http://zengzheming.gitee.io/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20190816091220102.png">
<meta property="og:image" content="http://zengzheming.gitee.io/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20200319191202.png">
<meta property="og:image" content="http://zengzheming.gitee.io/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20200319191632.png">
<meta property="article:published_time" content="2020-03-19T16:02:48.000Z">
<meta property="article:modified_time" content="2020-03-31T13:55:11.621Z">
<meta property="article:author" content="Zengzheming">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://zengzheming.gitee.io/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20190816090744338.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://zengzheming.gitee.io/2020/03/20/tf1-13环境搭建/"/>





  <title>tf1.13环境搭建 | 曾哲明的博客</title>
  








<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">曾哲明的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">努力成为高级打杂</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://zengzheming.gitee.io/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Zengzheming">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="曾哲明的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">tf1.13环境搭建</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-03-20T00:02:48+08:00">
                2020-03-20
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" itemprop="url" rel="index">
                    <span itemprop="name">环境搭建</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>最近深度系统编译jni太卡，基本编译2次要重启一次，决定重装麒麟系统，重装显卡驱动和cuda10.1和cudnn和重新编译tensorflow1.13.2安装包。</p>
<p>参考如下：<br><a href="https://www.jianshu.com/p/9384af4896f3" target="_blank" rel="noopener">Ubuntu18.04安装nvidia显卡驱动</a><br><a href="https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-18-04-bionic-beaver-linux#h7-automatic-install-using-ppa-repository-to-install-nvidia-beta-drivers" target="_blank" rel="noopener">How to install the NVIDIA drivers on Ubuntu 18.04 Bionic Beaver Linux</a><br><a href="https://blog.csdn.net/BigData_Mining/article/details/99670642" target="_blank" rel="noopener">Ubuntu18.04下安装Nvidia驱动和CUDA10.1＋CUDNN</a><br><a href="https://docs.nvidia.com/deeplearning/sdk/cudnn-archived/cudnn_713/cudnn-install/index.html" target="_blank" rel="noopener">DEEP LEARNING SDK DOCUMENTATION</a><br><a href="https://www.cnblogs.com/carle-09/p/11675473.html" target="_blank" rel="noopener">版本问题—-Bazel与tensorflow的对应关系</a><br><a href="https://developer.nvidia.com/cuda-gpus" target="_blank" rel="noopener">GPU Compute Capability</a><br><a href="https://blog.csdn.net/Tosonw/article/details/89884948" target="_blank" rel="noopener">TensorFlow编译安装（Linux）</a><br><a href="https://tensorflow.google.cn/install/source" target="_blank" rel="noopener">从源代码构建</a></p>
<h1 id="nvidia驱动安装"><a href="#nvidia驱动安装" class="headerlink" title="nvidia驱动安装"></a>nvidia驱动安装</h1><h2 id="禁用显卡"><a href="#禁用显卡" class="headerlink" title="禁用显卡"></a>禁用显卡</h2><p>在<code>/etc/modprobe.d/blacklist.conf</code>里添加，如下内容，并执行 <code>sudo update-initramfs -u</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">blacklist nouveau</span><br><span class="line">options nouveau modeset&#x3D;0</span><br><span class="line">$ sudo dpkg --add-architecture i386</span><br><span class="line">$ sudo apt update</span><br><span class="line">$ sudo apt install build-essential libc6:i386 libglvnd-dev pkg-config</span><br></pre></td></tr></table></figure><br>重启后用<code>lsmod | grep nouveau</code>,如果没有任何输出说明禁用成功</p>
<h2 id="下载nvidia驱动"><a href="#下载nvidia驱动" class="headerlink" title="下载nvidia驱动"></a>下载nvidia驱动</h2><p>在<code>https://www.nvidia.cn/Download/index.aspx?lang=cn</code>中下载显卡对应驱动</p>
<h2 id="手动nvidia驱动"><a href="#手动nvidia驱动" class="headerlink" title="手动nvidia驱动"></a>手动nvidia驱动</h2><p>重启电脑，在命令行中输入命令<code>sudo telinit 3</code><br>然后按下<code>CTRL+ALT+F1</code>输入用户名和密码<br>登陆后输入<code>$ sudo bash NVIDIA-Linux-x86_64-410.73.bin</code>安装nVidia驱动<br>最后重启系统<code>$ sudo reboot</code>,键入<code>nvidia-smi</code>进行验证，如果出现<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">$ nvidia-smi</span><br><span class="line">Fri Aug 16 08:46:25 2019     </span><br><span class="line">+-----------------------------------------------------------------------------+</span><br><span class="line">| NVIDIA-SMI 430.26       Driver Version: 430.26       CUDA Version: 10.2     |</span><br><span class="line">|-------------------------------+----------------------+----------------------+</span><br><span class="line">| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |</span><br><span class="line">| Fan  Temp  Perf  Pwr:Usage&#x2F;Cap|         Memory-Usage | GPU-Util  Compute M. |</span><br><span class="line">|&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;+&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;+&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;|</span><br><span class="line">|   0  GeForce 940MX       Off  | 00000000:3C:00.0 Off |                  N&#x2F;A |</span><br><span class="line">| N&#x2F;A   46C    P0    N&#x2F;A &#x2F;  N&#x2F;A |    183MiB &#x2F;  2004MiB |      3%      Default |</span><br><span class="line">+-------------------------------+----------------------+----------------------+</span><br><span class="line">                                                                               </span><br><span class="line">+-----------------------------------------------------------------------------+</span><br><span class="line">| Processes:                                                       GPU Memory |</span><br><span class="line">|  GPU       PID   Type   Process name                             Usage      |</span><br><span class="line">|&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;|</span><br><span class="line">|    0      3038      G   &#x2F;usr&#x2F;lib&#x2F;xorg&#x2F;Xorg                            94MiB |</span><br><span class="line">|    0      4709      G   &#x2F;usr&#x2F;bin&#x2F;gnome-shell                          86MiB |</span><br><span class="line">+-----------------------------------------------------------------------------+</span><br></pre></td></tr></table></figure></p>
<h1 id="cuda10-1-cudnn7-6安装"><a href="#cuda10-1-cudnn7-6安装" class="headerlink" title="cuda10.1+cudnn7.6安装"></a>cuda10.1+cudnn7.6安装</h1><h2 id="安装cuda10-1"><a href="#安装cuda10-1" class="headerlink" title="安装cuda10.1"></a>安装cuda10.1</h2><p>在<code>http://developer.nvidia.com/cuda-downloads</code>中下载cuda10.1版本的安装包<br>输入<code>sudo sh cuda_10.1.243_418.87.00_linux.run</code>进行安装，注意不要勾选驱动<br><img src="/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20190816090744338.png" alt="avatar"><br>安装完cuda10.1在~/.bashrc中添加环境变量：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">export PATH&#x3D;&quot;&#x2F;usr&#x2F;local&#x2F;cuda-10.1&#x2F;bin:$PATH&quot;</span><br><span class="line">export LD_LIBRARY_PATH&#x3D;&quot;&#x2F;usr&#x2F;lcoal&#x2F;cuda-10.1&#x2F;lib64:$LD_LIBRARY_PATH&quot;</span><br></pre></td></tr></table></figure><br>激活环境变量：<br><code>source ~/.bashrc</code><br>验证cuda10.1：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;usr&#x2F;local&#x2F;cuda-10.1&#x2F;samples&#x2F;1_Utilities&#x2F;deviceQuery</span><br><span class="line">sudo make</span><br><span class="line">.&#x2F;deviceQuery</span><br></pre></td></tr></table></figure><br><img src="/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20190816091220102.png" alt="avatar"><br>出现Result = PASS则表示安装成功通过!!</p>
<h2 id="安装cudnn7-6"><a href="#安装cudnn7-6" class="headerlink" title="安装cudnn7.6"></a>安装cudnn7.6</h2><ul>
<li><a href="https://developer.nvidia.com/rdp/cudnn-archive" target="_blank" rel="noopener">下载cuDNN v7.6.1 (June 24, 2019), for CUDA 10.1</a></li>
<li><code>sudo dpkg -i libcudnn7_7.0.3.11-1+cuda9.0_amd64.deb</code></li>
<li><code>sudo dpkg -i libcudnn7-dev_7.0.3.11-1+cuda9.0_amd64.deb</code></li>
<li><code>sudo dpkg -i libcudnn7-doc_7.0.3.11-1+cuda9.0_amd64.deb</code></li>
</ul>
<h1 id="编译tensorflow1-13-2"><a href="#编译tensorflow1-13-2" class="headerlink" title="编译tensorflow1.13.2"></a>编译tensorflow1.13.2</h1><p>tensorflow的编译需要对应bazel的版本号，这里选择的版本号是Bazel 0.19.2<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git clone https:&#x2F;&#x2F;github.com&#x2F;tensorflow&#x2F;tensorflow.git</span><br><span class="line">cd tensorflow</span><br><span class="line">git checkout r1.13.2  # r1.9, r1.10, etc.</span><br><span class="line">.&#x2F;configure</span><br></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;configure</span><br><span class="line">  You have bazel 0.15.0 installed.</span><br><span class="line">  Please specify the location of python. [Default is &#x2F;usr&#x2F;bin&#x2F;python]: &#x2F;usr&#x2F;bin&#x2F;python2.7</span><br><span class="line"></span><br><span class="line">  Found possible Python library paths:</span><br><span class="line">    &#x2F;usr&#x2F;local&#x2F;lib&#x2F;python2.7&#x2F;dist-packages</span><br><span class="line">    &#x2F;usr&#x2F;lib&#x2F;python2.7&#x2F;dist-packages</span><br><span class="line">  Please input the desired Python library path to use.  Default is [&#x2F;usr&#x2F;lib&#x2F;python2.7&#x2F;dist-packages]</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with jemalloc as malloc support? [Y&#x2F;n]:</span><br><span class="line">  jemalloc as malloc support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with Google Cloud Platform support? [Y&#x2F;n]:</span><br><span class="line">  Google Cloud Platform support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with Hadoop File System support? [Y&#x2F;n]:</span><br><span class="line">  Hadoop File System support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with Amazon AWS Platform support? [Y&#x2F;n]:</span><br><span class="line">  Amazon AWS Platform support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with Apache Kafka Platform support? [Y&#x2F;n]:</span><br><span class="line">  Apache Kafka Platform support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with XLA JIT support? [y&#x2F;N]:</span><br><span class="line">  No XLA JIT support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with GDR support? [y&#x2F;N]:</span><br><span class="line">  No GDR support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with VERBS support? [y&#x2F;N]:</span><br><span class="line">  No VERBS support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with OpenCL SYCL support? [y&#x2F;N]:</span><br><span class="line">  No OpenCL SYCL support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with CUDA support? [y&#x2F;N]: Y</span><br><span class="line">  CUDA support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 9.0]: 10.1</span><br><span class="line"></span><br><span class="line">  Please specify the location where CUDA 9.0 toolkit is installed. Refer to README.md for more details. [Default is &#x2F;usr&#x2F;local&#x2F;cuda]:</span><br><span class="line"></span><br><span class="line">  Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 7.5</span><br><span class="line"></span><br><span class="line">  Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is &#x2F;usr&#x2F;local&#x2F;cuda]:</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with TensorRT support? [y&#x2F;N]:</span><br><span class="line">  No TensorRT support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Please specify the NCCL version you want to use. If NCLL 2.2 is not installed, then you can use version 1.3 that can be fetched automatically but it may have worse performance with multiple GPUs. [Default is 2.2]: 1.3</span><br><span class="line"></span><br><span class="line">  Please specify a list of comma-separated Cuda compute capabilities you want to build with.</span><br><span class="line">  You can find the compute capability of your device at: https:&#x2F;&#x2F;developer.nvidia.com&#x2F;cuda-gpus.</span><br><span class="line">  Please note that each additional compute capability significantly increases your</span><br><span class="line">  build time and binary size. [Default is: 3.5,7.0] 7.5</span><br><span class="line"></span><br><span class="line">  Do you want to use clang as CUDA compiler? [y&#x2F;N]:</span><br><span class="line">  nvcc will be used as CUDA compiler.</span><br><span class="line"></span><br><span class="line">  Please specify which gcc should be used by nvcc as the host compiler. [Default is &#x2F;usr&#x2F;bin&#x2F;gcc]:</span><br><span class="line"></span><br><span class="line">  Do you wish to build TensorFlow with MPI support? [y&#x2F;N]:</span><br><span class="line">  No MPI support will be enabled for TensorFlow.</span><br><span class="line"></span><br><span class="line">  Please specify optimization flags to use during compilation when bazel option &quot;--config&#x3D;opt&quot; is specified [Default is -march&#x3D;native]:</span><br><span class="line"></span><br><span class="line">  Would you like to interactively configure .&#x2F;WORKSPACE for Android builds? [y&#x2F;N]:</span><br><span class="line">  Not configuring the WORKSPACE for Android builds.</span><br><span class="line"></span><br><span class="line">  Preconfigured Bazel build configs. You can use any of the below by adding &quot;--config&#x3D;&lt;&gt;&quot; to your build command. See tools&#x2F;bazel.rc for more details.</span><br><span class="line">      --config&#x3D;mkl            # Build with MKL support.</span><br><span class="line">      --config&#x3D;monolithic     # Config for mostly static monolithic build.</span><br><span class="line">  Configuration finished</span><br></pre></td></tr></table></figure>
<p>注意：RTX2070s 的 Compute Capability 为 7.5</p>
<p>编译：<code>bazel build //tensorflow/tools/pip_package:build_pip_package</code></p>
<ul>
<li><p>由于在编译的过程中，要下载大量的包，这里使用的离线下载依赖包的方法：<br>启动download_server.py脚本，把无法下载的，大的文件放在download_files文件夹中<br><img src="/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20200319191202.png" alt="avatar"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">#coding:utf-8</span><br><span class="line">from flask import Flask, request, jsonify, send_from_directory, abort</span><br><span class="line">import os</span><br><span class="line">from flask import make_response</span><br><span class="line"></span><br><span class="line">app &#x3D; Flask(__name__)</span><br><span class="line"></span><br><span class="line">@app.route(&quot;&#x2F;download&#x2F;&lt;filename&gt;&quot;, methods&#x3D;[&#39;GET&#39;])</span><br><span class="line">def download_file(filename):</span><br><span class="line">    cur_dir &#x3D; os.getcwd()</span><br><span class="line">    files_dir &#x3D; os.path.join(cur_dir, &#39;download_files&#39;)</span><br><span class="line">    response &#x3D; make_response(send_from_directory(files_dir, filename, as_attachment&#x3D;True, mimetype&#x3D;&#39;application&#x2F;octet-stream&#39;))</span><br><span class="line">    response.headers[&quot;Content-Disposition&quot;] &#x3D; &quot;attachment; filename&#x3D;&#123;&#125;&quot;.format(filename.encode().decode(&#39;latin-1&#39;))</span><br><span class="line">    return response</span><br><span class="line"></span><br><span class="line">@app.route(&#39;&#x2F;hello&#39;)</span><br><span class="line">def hello():</span><br><span class="line">    return &#39;Hello world.&#39;</span><br><span class="line"></span><br><span class="line">if __name__ &#x3D;&#x3D; &#39;__main__&#39;:</span><br><span class="line">    app.run(host&#x3D;&#39;0.0.0.0&#39;,port&#x3D;8888)</span><br></pre></td></tr></table></figure>
<p>修改<code>tensorflow/workspace.bzl</code>和<code>third_party/icu/workspace.bzl</code>文件，如：<br><img src="/blog/2020/03/20/tf1-13%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/20200319191632.png" alt="avatar"></p>
</li>
<li><p>编译过程中会出现一些报错，如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#找不到库文件</span><br><span class="line">Cuda Configuration Error: Cannot find cuda library libcublas.so.10.1</span><br></pre></td></tr></table></figure>
<p>解决方案：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">find &#x2F;usr -name libcublas*</span><br><span class="line">cd &#x2F;usr&#x2F;lib&#x2F;x86_64-linux-gnu&#x2F;</span><br><span class="line">ls -l libcublas*</span><br><span class="line">cd &#x2F;usr&#x2F;local&#x2F;cuda-10.1&#x2F;targets&#x2F;x86_64-linux&#x2F;lib</span><br><span class="line">sudo ln -s &#x2F;usr&#x2F;lib&#x2F;x86_64-linux-gnu&#x2F;libcublas.so.10.1 libcublas.so.10.1</span><br><span class="line"></span><br><span class="line">sudo ln -s libcusolver.so.10 libcusolver.so.10.1</span><br><span class="line">sudo ln -s libcurand.so.10 libcurand.so.10.1</span><br><span class="line">sudo ln -s libcufft.so.10 libcufft.so.10.1</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>生成whl：<code>./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg</code></p>
<p>生成tensorflowLite.so：<br>在<code>tensorflow/lite/BUILD</code>中添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">cc_binary(</span><br><span class="line">    name &#x3D; &quot;libtensorflowLite.so&quot;,</span><br><span class="line">    linkopts &#x3D; [&quot;-shared&quot;, &quot;-Wl,-soname&#x3D;libtensorflowLite.so&quot;],</span><br><span class="line">    visibility &#x3D; [&quot;&#x2F;&#x2F;visibility:public&quot;],</span><br><span class="line">    linkshared &#x3D; 1,</span><br><span class="line">    copts &#x3D; tflite_copts(),</span><br><span class="line">    deps &#x3D; [</span><br><span class="line">        &quot;:framework&quot;,</span><br><span class="line">        &quot;&#x2F;&#x2F;tensorflow&#x2F;lite&#x2F;kernels:builtin_ops&quot;,</span><br><span class="line">    ],</span><br><span class="line">)</span><br></pre></td></tr></table></figure><br>编译：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bazel build -c opt &#x2F;&#x2F;tensorflow&#x2F;lite:libtensorflowLite.so   --crosstool_top&#x3D;&#x2F;&#x2F;external:android&#x2F;crosstool --cpu&#x3D;armeabi-v7a --host_crosstool_top&#x3D;@bazel_tools&#x2F;&#x2F;tools&#x2F;cpp:toolchain --cxxopt&#x3D;&quot;-std&#x3D;c++11&quot; --verbose_failures</span><br></pre></td></tr></table></figure></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2020/03/19/v2ray%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" rel="next" title="v2ray环境搭建">
                <i class="fa fa-chevron-left"></i> v2ray环境搭建
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2020/03/20/MTCNN%E9%98%85%E8%AF%BB/" rel="prev" title="MTCNN阅读">
                MTCNN阅读 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Zengzheming</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/%7C%7Carchive">
              
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#nvidia驱动安装"><span class="nav-number">1.</span> <span class="nav-text">nvidia驱动安装</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#禁用显卡"><span class="nav-number">1.1.</span> <span class="nav-text">禁用显卡</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#下载nvidia驱动"><span class="nav-number">1.2.</span> <span class="nav-text">下载nvidia驱动</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#手动nvidia驱动"><span class="nav-number">1.3.</span> <span class="nav-text">手动nvidia驱动</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#cuda10-1-cudnn7-6安装"><span class="nav-number">2.</span> <span class="nav-text">cuda10.1+cudnn7.6安装</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#安装cuda10-1"><span class="nav-number">2.1.</span> <span class="nav-text">安装cuda10.1</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装cudnn7-6"><span class="nav-number">2.2.</span> <span class="nav-text">安装cudnn7.6</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#编译tensorflow1-13-2"><span class="nav-number">3.</span> <span class="nav-text">编译tensorflow1.13.2</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Zengzheming</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

</body>
</html>
